package cn.iocoder.yudao.module.erp.dal.mysql.saleorder;

import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.erp.dal.dataobject.saleorder.SaleOrderGoodsDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collection;
import java.util.List;

/**
 * 销售单和物品的链接表-多对多关系 Mapper
 *
 * @author maxuxu
 */
@Mapper
public interface SaleOrderGoodsMapper extends BaseMapperX<SaleOrderGoodsDO> {

    default List<SaleOrderGoodsDO> selectListByOrderId(Long orderId) {
        return selectList(SaleOrderGoodsDO::getOrderId, orderId);
    }

    default void deleteByOrderId(Long orderId) {
        delete(SaleOrderGoodsDO::getOrderId, orderId);
    }

    default void deleteByOrderIds(Collection<Long> orderIds) {
        delete(new QueryWrapper<SaleOrderGoodsDO>().in("order_id", orderIds));
    }

    default SaleOrderGoodsDO selectByOrderIdGoodsId(Long orderId, Long goodsId) {
        return selectOne(SaleOrderGoodsDO::getOrderId, orderId,
                SaleOrderGoodsDO::getGoodsId, goodsId);
    }

    default List<SaleOrderGoodsDO> selectListByOrderIdGoodsIds(Long orderId, List<Long> goodsIds) {
        return selectList(new LambdaQueryWrapper<SaleOrderGoodsDO>()
                .eq(SaleOrderGoodsDO::getOrderId, orderId).in(SaleOrderGoodsDO::getGoodsId, goodsIds));
    }

}